﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Outpatient
{
    /// <summary>
    /// 门诊操作间
    /// </summary>
    public class OtpOperRmService : CrudAppService<OtpOperRm, OtpOperRmDto, Guid, OtpOperRmInput, OtpOperRmCreateOrUpdateDto, OtpOperRmCreateOrUpdateDto>, IOtpOperRmService
    {
        private IRepository<OtpOperRm, Guid> _otpOperRmRepository;

        public OtpOperRmService(IRepository<OtpOperRm, Guid> otpOperRmRepository) : base(otpOperRmRepository)
        {
            _otpOperRmRepository = otpOperRmRepository;
        }

        public override async Task<PagedResultDto<OtpOperRmDto>> GetListAsync(OtpOperRmInput input)
        {
            var iQuery = await _otpOperRmRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<OtpOperRm>, List<OtpOperRmDto>>(iQuery.ToList());

                return new PagedResultDto<OtpOperRmDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<OtpOperRm>, List<OtpOperRmDto>>(items.ToList());

                return new PagedResultDto<OtpOperRmDto>(totalCount, itemsDto);
            }
        }
    }
}
